package com.aldobucchi.core.os
{
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import com.aldobucchi.core.os.thread.Thread;
	import com.aldobucchi.x.flash.events.EventListenerSpec;

	public class SimpleRunnable extends EventDispatcher
	{
		
		
		private var _name:String;
		
		public function get name( ):String
		{
			return _name;
		}
		
		
		public function SimpleRunnable( name:String )
		{
			_name = name;
		}
		

		
		public function step1( ):void
		{
			fyi( "step1" );		
			Thread.current.queue( step2 );
		}		
		

		
		private function step2( ):void
		{
			fyi( "step2" );		
			Thread.current.queue( step3 );
		}		
		
		

		private function step3( ):void
		{
			fyi( "step3" );
			
			var t:Timer = new Timer( 2000, 1 );
			var els:* = new EventListenerSpec( TimerEvent.TIMER_COMPLETE, timer_complete );
			
			Thread.current.queueAsyncUsingListener( t.start, null, t, [ els ] );
		}		

		
		private function timer_complete( event:TimerEvent ):void
		{
			
			fyi( "timer complete!" );
			Thread.current.queue( step4 );
		}


		private function step4( ):void
		{
			fyi( "step4" );		
		}
		
		
		
		private function fyi( str:String ):void
		{
			trace( _name + " " + str );	
		}
		
		
	}


}